import requests
from bs4 import BeautifulSoup
import json
import PgTool as pg

headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
    "accept": "application/json, text/javascript, */*; q=0.01",
}
url = "https://www.zhipin.com/wapi/zpgeek/common/data/citysites.json"
cities = []
res = requests.get(url, headers=headers, timeout=10)
print(res.text)
citiesObj = json.loads(res.text)
zpData = citiesObj["zpData"]
for city in zpData:
    code = str(city["code"])
    name = city["name"]
    cityurl = city["url"]

    sql = "INSERT INTO boss_cities(code, name, url) VALUES ('"+code+"', '"+name+"', '"+cityurl+"')"

    pg.insert(sql)





